﻿/* Required:    
1. jquery.slimScroll.js
*/

function CScroll(opts) {
    var self = this;
    this.container = "";
    this.options = {
        wheelStep: 20,
        width: 'auto',
        height: '250px',
        size: '7px',
        color: '#999',
        position: 'right',
        distance: '1px',
        start: 'top',
        opacity: .4,
        alwaysVisible: false,
        disableFadeOut: false,
        railVisible: false,
        railColor: '#555',
        railOpacity: '0.2',
        railClass: 'slimScrollRail',
        barClass: 'slimScrollBar',
        wrapperClass: 'slimScrollDiv',
        allowPageScroll: false,
        scroll: 0,
        touchScrollStep: 200
    };
    $.extend(this.options, opts);
    this.Init = function (container) {
        self.container = container;
        /* if existed then remove*/
        var $slimScroll = $(container).parent();
        if ($slimScroll.hasClass("slimScrollDiv")) {
            $(container).insertBefore($slimScroll);
            $slimScroll.remove();
        }
        /* create scroll */
        $(container).slimScroll(self.options);
    };
    this.Refresh = function (opts) {
        $.extend(self.options, opts);
        var container = self.container;
        self.Remove();
        self.Init(container);
    };
    this.Remove = function () {
        var container = self.container;
        var $slimScroll = $(container).parent(".slimScrollDiv");
        if ($slimScroll.length) {
            $(container).insertBefore($slimScroll);
            $slimScroll.remove();
            $(container).css("height", "auto");
        }
    };
}